package com.action;

import java.util.List;

import com.entity.School;
import com.service.ISchoolService;
import com.service.impl.SchoolService;
import com.tools.MyTools;
import com.tools.Page;

/**
 * school action
 * @author Administrator
 *
 */
public class SchoolAction {
	
	private ISchoolService schoolService;
	
	private School school;
	
	private List<School> list;
	
	private Page page;
	
	/**
	 * 初始化page分页
	 */
	private void pageInit(){
		if(page==null){
			page=new Page(1, 15);
		}
		else{
			if(page.getSize()==0 || page.getSize()>100){
				page.setSize(15);
			}
		}
	}
	
	
	/**
	 * 添加
	 * @return
	 */
	public String add(){
		pageInit();
		schoolService=new SchoolService();
		school.setId(MyTools.getId(20));
		if(schoolService.add(school)){
			return "success";
		}
		return "error";
	}
	
	/**
	 * 修改
	 * @return
	 */
	public String update(){
		pageInit();
		schoolService=new SchoolService();
		schoolService.count(page);
		if(schoolService.update(school)){
			return "success";
		}
		
		return "error";
	}
	
	/**
	 * 查询一个
	 * @return
	 */
	public String findById(){
		pageInit();
		schoolService=new SchoolService();
		school=schoolService.findById(school.getId());
		schoolService.count(page);
		return "success";
	}
	
	/**
	 * 查询一组
	 * @return
	 */
	public String getAll(){
		pageInit();
		schoolService=new SchoolService();
		list=schoolService.getList(page);
		return "success";
	}
	
	public String to(){
		return "success";
	}

	public School getSchool() {
		return school;
	}

	public void setSchool(School school) {
		this.school = school;
	}

	public List<School> getList() {
		return list;
	}

	public void setList(List<School> list) {
		this.list = list;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}
	
	
	
}
